<template>
  <div class="scroll-notice">
    <el-scroll-container :height="scrollHeight" :wrap-content="false">
      <div class="scroll-content">
        {{ content }}
      </div>
    </el-scroll-container>
  </div>
</template>

<script>
export default {
  name: 'ScrollNotice',
  props: {
    content: {
      type: String,
      required: true
    },
    duration: {
      type: Number,
      default: 3000 // 公告滚动的间隔时间，单位为毫秒
    },
    scrollHeight: {
      type: Number,
      default: 30 // 公告容器的高度，单位为像素
    }
  },
  data() {
    return {
      intervalId: null
    };
  },
  mounted() {
    this.intervalId = setInterval(() => {
      this.$elScrollContainer.setScrollTop(0);
    }, this.duration);
  },
  beforeDestroy() {
    clearInterval(this.intervalId);
  }
};
</script>

<style scoped>
.scroll-notice {
  width: 100%;
  overflow: hidden;
  white-space: nowrap;
}

.scroll-content {
  display: inline-block;
  padding: 10px;
  color: #333;
  background-color: #f8f8f8;
  border-radius: 4px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  line-height: 30px; /* 根据需要调整 */
}
</style>
